#pragma once

#include "AsyncTask.h"

using namespace AT;

class CThreadpool;
class COrderedTask;
class CDelayedTask;
class CUIThreadTask;

class CAsyncTask : public IAsyncTask
{
public:
	CAsyncTask();
	~CAsyncTask();

	bool Init() override;
	void Exit() override;
	bool AsyncTask(ICallbackPtr&& pTask) override;
	bool OrderedTask(CValueKey key, ICallbackPtr&& pTask) override;
	bool DelayedTask(UINT nDelayMs, ICallbackPtr&& pTask) override;
	bool UIAsyncTask(ICallbackPtr&& pTask) override;
	bool UIDelayedTask(UINT nDelayMs, ICallbackPtr&& pTask) override;

private:
	std::atomic_uint m_nLastTaskId;
	bool             m_bInited;
	SRWLOCK          m_SRWLock = SRWLOCK_INIT;
	std::unique_ptr<CThreadpool> m_pThreadpool;
	std::unique_ptr<COrderedTask> m_pOrderedTask;
	std::unique_ptr<CDelayedTask> m_pDelayedTask;
	std::unique_ptr<CUIThreadTask> m_pUIThreadTask;
};
